!pr0
!lm12
!rm75
Programming a Language Card.........................Bill Morgan

Recently we've received a couple of questions about the exact meaning of all those $C08x addresses used to access a language (or RAM) card in slot 0.  Here's a rundown of what memory cards are and how to use them.

A RAM card is a plug-in board containing an extra 16K (or more) of memory, which can be used instead of the language ROMs on your Apple motherboard.  The $C08x addresses are switches that determine which memory will be used whenever you read or write an address from $D000-$FFFF.  With the proper use of the switches on a 16K card, your Apple becomes a machine with 76K of memory!  (That includes motherboard RAM, motherboard ROM, and the full RAM card.)

Here's a summary of the addresses and their functions:


    Address      Read      Write     Bank
    -------      ----      -----     ----
     $C080       Card      Mother      2
     $C081*      Mother    Card        2
     $C082       Mother    Mother      2
     $C083*      Card      Card        2

     $C088       Card      Mother      1
     $C089*      Mother    Card        1
     $C08A       Mother    Mother      1
     $C08B*      Card      Card        1


The stars indicate addresses which must be accessed twice to have effect (these are the ones that write-enable the card.)

These addresses are "soft switches", much like those for switching the screen display modes.  To throw a switch, just use a LDA or any instruction that reads the location.  From BASIC you can use a PEEK.  STA or POKE also work with most RAM cards, but not all of them.  Experiment with yours to see how it behaves.  If you're writing a program for use on other people's Apples it's safest to stay with instructions that read the location.

The Bank column refers to the fact that a language card actually has 16K of memory, but the range from $D000 to $FFFF is only 12K.  The other 4K ought to be $C000-$CFFF, but that's the area that Apple uses for special Input/Output functions.  Therefore, there is an extra 4K "bank" which can be addressed at $D000-DFFF.  Normally, only Bank 2 is used.  If a program gets bigger than 12K it becomes necessary to use Bank 1, but that starts getting complicated.  The best approach is to put routines or data in bank 1 that don't have to refer to anything in bank 2.  You can then have the main code above $E000 decide which bank to use.
!np
Some programs seem to use the motherboard and RAM card memories at the same time.  Examples of this are ES-CAPE.LC and the programs that relocate DOS into the RAM card.  Generally, these have a short "bridge" or "switcher" routine somewhere in the motherboard RAM.  When the program in the RAM card needs to call a routine in the motherboard ROM, it actually calls the bridge.  The bridge routine then throws the appropriate $C08x switches and calls the necessary ROM routine.  When that routine finishes, the bridge then switches back to the RAM card and continues the program there.

Another thing to consider is whether the program in the RAM card needs the system monitor.  If so, you need to make sure there is a copy of the monitor on the RAM card.  Here's how to use the monitor to copy itself into a RAM card:

     ]CALL-151
     *C081 C081
     *F800<F800.FFFFM

That monitor move instruction looks like nonsense, but remember that the $C081 switch sets the computer to read from the motherboard and write to the RAM card.
